import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'state.dart';

class MkWebviewController extends GetxController {
  final MkWebviewState state = MkWebviewState();

  WebViewController webViewController = WebViewController()
    ..setJavaScriptMode(JavaScriptMode.unrestricted)
    ..setNavigationDelegate(
      NavigationDelegate(
        onProgress: (int progress) {
          // Update loading bar.
        },
        onPageStarted: (String url) {},
        onPageFinished: (String url) {},
        onWebResourceError: (WebResourceError error) {},
        onNavigationRequest: (NavigationRequest request) {
          return NavigationDecision.navigate;
        },
      ),
    );
  final String url = Get.arguments['url'];
  final String title = Get.arguments['title'];

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    state.title = title;

    webViewController..loadRequest(Uri.parse(url));
  }
}
